﻿#include "AttributeSetDialog.h"
#include "ui_AttributeSetDialog.h"
#include <QMessageBox>

namespace GUI
{
    AttributeSetDialog::AttributeSetDialog(int valueType, QWidget* p /*= nullptr*/)
        :_ui(new Ui::AttributeSetDialog),_valueType(valueType)
    {
        _ui->setupUi(this);
        //不是关闭之后直接析构
        this->setAttribute(Qt::WA_DeleteOnClose, false);
        if(valueType==2)
        _ui->stackedWidget->setCurrentIndex(1);

    }

    void AttributeSetDialog::setTextLabel(const QString& text)
    {
        _ui->textLabel->setText(text);
    }

    void AttributeSetDialog::setDefaultValueDouble(const double v)
    {
        QString  text = QString::number(v);
        _ui->valueLineEdit->setText(text);
    }

    void AttributeSetDialog::setDefaultValueQString(const QList<QString>& list)
    {
        for (auto v : list) {
            _ui->valueComboBox->addItem(v);
        }
    }

    QString AttributeSetDialog::getValueQString()
    {
        return _ui->valueComboBox->currentText();
    }

    double AttributeSetDialog::getValueDouble()
    {
        return _ui->valueLineEdit->text().toDouble();
    }

    void AttributeSetDialog::accept()
    {
        bool ok = true;
        //错误检查
        switch (_valueType)
        {
        case 1: //输入浮点数字
            _ui->valueLineEdit->text().toDouble(&ok); break;
        default:
            break;
        }
        if (!ok)
        {
            //错误警告
            QMessageBox::warning(this, QString(tr("Warning")), QString(tr("Wrong Input Value !")));
            return;
        }
        Core::FITKDialog::accept();
    }
}


